#include <nice2d/application.h>
#include <nice2d/string.h>
#include <nice2d/piece/factionmanager.h>
#include <nice2d/components/spritestatus.h>
#include "pieceinfo.h"

PieceInfo::PieceInfo():
    TextTable(8, 2)
{
}

PieceInfo::~PieceInfo()
{
}

void PieceInfo::init()
{
    setRowHeight(24);
    setColWidth(0, 48);
    setColWidth(1, 64);
}

void PieceInfo::setPiece(std::shared_ptr<Piece> piece)
{
    if (piece) {
        setText(L"名称", 0, 0);
        setText(L"势力", 1, 0);
        setText(L"状态", 2, 0);
        setText(L"类别", 3, 0);
        setText(L"生命", 4, 0);
        setText(L"攻击", 5, 0);
        setText(L"防御", 6, 0);
        setText(L"移动", 7, 0);

        setText(piece->getName(), 0, 1);

        auto factionmanager = GET_COMPONENT(Application::getInstance(), FactionManager);
        auto faction = factionmanager->getFaction(piece->getSpriteColor());

        setText(faction->getName(), 1, 1);
        setText(L"通常", 2, 1);
        setText(L"步兵", 3, 1);
        setText(std::to_string(piece->getHitPoint()), 4, 1);
        setText(std::to_string(piece->getAttack()), 5, 1);
        setText(std::to_string(piece->getDefence()), 6, 1);
        setText(std::to_string(piece->getMovement()), 7, 1);
    }
}
